home *** CD-ROM | disk | FTP | other *** search
/ SGI Developer Toolbox 6.1 / SGI Developer Toolbox 6.1 - Disc 4.iso / src / exampleCode / viewkit / VCal / OverviewDay.c++ < prev    next >
Encoding:
C/C++ Source or Header  |  1994-08-02  |  5.3 KB  |  202 lines

  1. /*
  2.  * Copyright (C) 1994, Silicon Graphics, Inc.
  3.  * All Rights Reserved.
  4.  *
  5.  * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
  6.  * the contents of this file may not be disclosed to third parties, copied or
  7.  * duplicated in any form, in whole or in part, without the prior written
  8.  * permission of Silicon Graphics, Inc.
  9.  *
  10.  * RESTRICTED RIGHTS LEGEND:
  11.  * Use, duplication or disclosure by the Government is subject to restrictions
  12.  * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
  13.  * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
  14.  * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
  15.  * rights reserved under the Copyright Laws of the United States.
  16.  */
  17. #include <stdio.h>
  18. #include "OverviewDay.h"
  19. #include "VCal.h"
  20. #include "DayView.h"
  21. #include "Entry.h"
  22. #include "Info.h"
  23.  
  24. #include <Xm/DrawingA.h>
  25.  
  26. static int count;
  27. static Arg args[10];
  28.  
  29. OverviewDay::OverviewDay(char *name, Widget parent, VCal *o)
  30. : VkComponent(name)
  31. {
  32.   XGCValues gcv;
  33.  
  34.   owner = o;
  35.  
  36.   day = month = year = 0;
  37.   today = False;
  38.   start = stop = 0;
  39.  
  40.   count = 0;
  41.   XtSetArg(args[count], XmNbackground, owner->normalColor());  count++;
  42.   XtSetArg(args[count], XmNborderColor, owner->nonHighlightColor());  count++;
  43.   _baseWidget = XmCreateDrawingArea(parent, name, args, count);
  44.   XtAddCallback(_baseWidget, XmNexposeCallback,
  45.         OverviewDay::area_expose, (XtPointer) this);
  46.   XtAddCallback(_baseWidget, XmNinputCallback,
  47.         OverviewDay::area_input, (XtPointer) this);
  48.  
  49.   gcv.foreground = owner->foregroundColor();
  50.   gcv.background = owner->normalColor();
  51.   gcLabel = XtGetGC(_baseWidget, GCForeground | GCBackground, &gcv);
  52.   gcv.foreground = owner->foregroundColor();
  53.   gcv.background = owner->annotateColor();
  54.   gcv.stipple = owner->getTile();
  55.   gcv.fill_style = FillOpaqueStippled;
  56.   gcAnnotate = XtGetGC(_baseWidget,
  57.                GCForeground | GCBackground | GCStipple | GCFillStyle,
  58.                &gcv);
  59. }
  60.  
  61. OverviewDay::~OverviewDay()
  62. {
  63.   XtRemoveCallback(_baseWidget, XmNexposeCallback,
  64.            OverviewDay::area_expose, (XtPointer) this);
  65.   XtRemoveCallback(_baseWidget, XmNinputCallback,
  66.            OverviewDay::area_input, (XtPointer) this);
  67.   XtReleaseGC(_baseWidget, gcLabel);
  68.   XtReleaseGC(_baseWidget, gcAnnotate);
  69. }
  70.  
  71. const char *
  72. OverviewDay::className()
  73. {
  74.   return "OverviewDay";
  75. }
  76.  
  77. /**********************************************************************/
  78.  
  79. void
  80. OverviewDay::setDate(int d, int m, int y, Boolean t, int s1, int s2)
  81. {
  82.   day = d;
  83.   month = m;
  84.   year = y;
  85.   today = t;
  86.   start = s1;
  87.   stop = s2;
  88.   display();
  89. }
  90.  
  91. /**********************************************************************/
  92.  
  93. void
  94. OverviewDay::display()
  95. {
  96.   char str[256];
  97.   XmString xs;
  98.   MemoryInfo *info;
  99.   Entry *entry;
  100.   RepeatingEntry *rentry;
  101.  
  102.   if (XtWindow(_baseWidget)) {
  103.     count = 0;
  104.     XtSetArg(args[count], XmNwidth, &width);  count++;
  105.     XtSetArg(args[count], XmNheight, &height);  count++;
  106.     XtGetValues(_baseWidget, args, count);
  107.     XClearWindow(XtDisplay(_baseWidget), XtWindow(_baseWidget));
  108.     if (day && month && year) {
  109.       count = 0;
  110.       if (today) {
  111.     XtSetArg(args[count], XmNborderColor,
  112.          owner->foregroundColor());  count++;
  113.       } else {
  114.     XtSetArg(args[count], XmNborderColor,
  115.          owner->nonHighlightColor());  count++;
  116.       }
  117.       XtSetValues(_baseWidget, args, count);
  118.       info = owner->findDateInfo(day, month, year);
  119.       if (info) {
  120.     info->rewind();
  121.     while (entry = info->nextEntry()) {
  122.       displayEntry(entry);
  123.     }
  124.       }
  125.       rentry = owner->getRepeatingEntries();
  126.       while (rentry->next()) {
  127.     rentry = rentry->next();
  128.     if (rentry->repeatApplies(day, month, year)) {
  129.       displayEntry(rentry);
  130.     }
  131.       }
  132.  
  133.       sprintf(str, "%d", day);
  134.       xs = XmStringCreateSimple(str);
  135.       XmStringDrawImage(XtDisplay(_baseWidget), XtWindow(_baseWidget),
  136.             owner->getLabelFont(), xs, gcLabel,
  137.             0, 2, XmStringWidth(owner->getLabelFont(), xs)+8,
  138.             XmALIGNMENT_CENTER, XmSTRING_DIRECTION_R_TO_L, NULL);
  139.     } else {
  140.       count = 0;
  141.       XtSetArg(args[count], XmNborderColor,
  142.            owner->normalColor());  count++;
  143.       XtSetValues(_baseWidget, args, count);
  144.     }
  145.   }
  146. }
  147.  
  148. void
  149. OverviewDay::displayEntry(Entry *entry)
  150. {
  151.   int y, h;
  152.   float total;
  153.  
  154.   total = stop-start;
  155.   y = (int) (0.5+height*(entry->start()-start)/total);
  156.   h = (int) (0.5+height*entry->length()/total);
  157.   if (h > 3) {
  158.     h -= 1;
  159.   }
  160.   XFillRectangle(XtDisplay(_baseWidget), XtWindow(_baseWidget),
  161.          gcAnnotate,
  162.          0, y, width, h);
  163. }
  164.  
  165. void
  166. OverviewDay::select()
  167. {
  168.   int nowDay, nowMonth, nowYear;
  169.  
  170.   if (day) {
  171.     owner->selectDay(day, month, year);
  172.     owner->getToday(&nowDay, &nowMonth, &nowYear);
  173.     if (day == nowDay && month == nowMonth && year == nowYear) {
  174.       owner->getDayView()->scrollToCurrentTime();
  175.     } else {
  176.       owner->getDayView()->scrollToBeginning();
  177.     }
  178.   }
  179. }
  180.  
  181. /**********************************************************************/
  182.  
  183. void
  184. OverviewDay::area_expose(Widget, XtPointer client_data, XtPointer)
  185. {
  186.   OverviewDay *obj = (OverviewDay *) client_data;
  187.  
  188.   obj->display();
  189. }
  190.  
  191. void
  192. OverviewDay::area_input(Widget, XtPointer client_data, XtPointer call_data)
  193. {
  194.   OverviewDay *obj = (OverviewDay *) client_data;
  195.   XmDrawingAreaCallbackStruct *cb = (XmDrawingAreaCallbackStruct *) call_data;
  196.  
  197.   if (cb->event && cb->event->type == ButtonPress &&
  198.       cb->event->xbutton.button == Button1) {
  199.     obj->select();
  200.   }
  201. }
  202.